home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
TUTORIAL
/
1307B.ZIP
/
LINKLIST.MOD
< prev
next >
Wrap
Text File
|
1989-01-18
|
2KB
|
89 lines
(* Chapter 12 - Program 3 *)
MODULE LinkList;
FROM InOut IMPORT WriteString, Write, WriteLn;
FROM Storage IMPORT ALLOCATE, DEALLOCATE, Available;
FROM SYSTEM IMPORT TSIZE;
TYPE NextPointer = POINTER TO FullName;
FullName = RECORD
FirstName : ARRAY[0..12] OF CHAR;
Initial : CHAR;
LastName : ARRAY[0..15] OF CHAR;
Next : NextPointer;
END;
VAR StartOfList : NextPointer;
PlaceInList : NextPointer;
TempPlace : NextPointer;
Index : CARDINAL;
Enough : BOOLEAN;
BEGIN (* Main Program *)
(* Generate the first name in the list *)
ALLOCATE(PlaceInList,TSIZE(FullName));
StartOfList := PlaceInList;
PlaceInList^.FirstName := "John ";
PlaceInList^.Initial := 'Q';
PlaceInList^.LastName := " Doe";
PlaceInList^.Next := NIL;
(* Generate another name in the list *)
TempPlace := PlaceInList;
ALLOCATE(PlaceInList,TSIZE(FullName));
TempPlace^.Next := PlaceInList;
PlaceInList^.FirstName := "Mary ";
PlaceInList^.Initial := 'R';
PlaceInList^.LastName := " Johnson";
PlaceInList^.Next := NIL;
(* Add 10 more names to complete the list *)
FOR Index := 1 TO 10 DO
TempPlace := PlaceInList;
Enough := Available(TSIZE(FullName)); (* Ignore result *)
ALLOCATE(PlaceInList,TSIZE(FullName));
TempPlace^.Next := PlaceInList;
PlaceInList^.FirstName := "Billy ";
PlaceInList^.Initial := 'R';
PlaceInList^.LastName := " Franklin";
PlaceInList^.Next := NIL;
END;
(* Display the list on the video monitor *)
PlaceInList := StartOfList;
REPEAT
WriteString(PlaceInList^.FirstName);
Write(PlaceInList^.Initial);
WriteString(PlaceInList^.LastName);
WriteLn;
TempPlace := PlaceInList;
PlaceInList := PlaceInList^.Next;
UNTIL TempPlace^.Next = NIL;
END LinkList.
(* Result of execution
John Q Doe
Mary R Johnson
Billy R Franklin
Billy R Franklin
Billy R Franklin
Billy R Franklin
Billy R Franklin
Billy R Franklin
Billy R Franklin
Billy R Franklin
Billy R Franklin
Billy R Franklin
*)